public class Solution1 {
    //53. 最大子数组和
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n]; //以i结尾的最大子数组的和
        dp[0] = nums[0];
        int ret = nums[0];
        for (int i = 1; i < n; i++) {
            dp[i] = Math.max(dp[i-1]+nums[i],nums[i]);
            ret = Math.max(ret,dp[i]);
        }
        return ret;
    }
}
